﻿using System.Linq;
using System.Web.Mvc;
using Omu.AwesomeDemo.Core.Model;
using Omu.AwesomeDemo.Core.Repository;
using Omu.AwesomeDemo.Infra.Dto;

namespace Omu.AwesomeDemo.WebUI.Controllers
{
    public class AjaxDropdownDemoController : BaseController
    {
        private readonly IRepo<Hobby> hobbyRepo;

        public AjaxDropdownDemoController(IRepo<Hobby> hobbyRepo)
        {
            this.hobbyRepo = hobbyRepo;
        }

        public ActionResult Index()
        {
            var input = new AjaxDropdownDemoInput
                            {
                                Country = 3,
                            };
            var h = hobbyRepo.GetAll().FirstOrDefault();
            if (h != null) input.HobbyGuid = h.IdGuid;
            ViewData["VCountry"] = 5;
            return View(input);
        }

        [HttpPost]
        public ActionResult Index(AjaxDropdownDemoInput input)
        {
            ViewData["VCountry"] = Request.Form["VCountry"];
            return View(input);
        }
    }
}